<!-- 编辑弹窗 -->
<template>
    <ele-modal
      width="30%"
      :visible="visible"
      :close-on-click-modal="true"
      custom-class="ele-dialog-form"
      title="订单配送"
      @update:visible="updateVisible"
    >
    <el-form ref="form" :model="form" :rules="rules" label-width="100px" >
        <el-card  style="margin-top: -10px">
            <el-row :gutter="20">
                <el-col :md="24" :sm="24">
                    <el-form-item label="订单号:">
                      {{showData.orderNo}}
                    </el-form-item>
                  </el-col>
                 
                <el-col :md="24" :sm="24">
                   <el-form-item label="配送平台:" prop="deliveryPlatform">
                    <el-input v-model="form.deliveryPlatform" placeholder="请输入配送平台" />
                    </el-form-item>
                  </el-col>
                  <el-col :md="24" :sm="24" >
                    <el-form-item label="配送单号:" prop="deliveryNo">
                        <el-input v-model="form.deliveryNo" placeholder="请输入配送单号" />
                    </el-form-item>
                  </el-col>
                  <el-col :md="24" :sm="24">
                    <el-form-item label="配送人:" prop="DeliveryUserName">
                        <el-input v-model="form.DeliveryUserName" placeholder="请输入配送人" />
                    </el-form-item>
                  </el-col>
                  <el-col :md="24" :sm="24">
                    <el-form-item label="配送电话:" prop="deliveryPhone">
                        <el-input v-model="form.deliveryPhone" placeholder="请输入配送电话" />
                    </el-form-item>
                  </el-col>
                  

              </el-row>
            
        </el-card>
        
    </el-form>
    <div slot="footer">
      <el-button @click="updateVisible(false)">取消</el-button>
      <el-button type="primary" :loading="loading" @click="save">
        保 存
      </el-button>
    </div>
    </ele-modal>
  </template>
  
  <script>
    //初始化对像
    import { QueryOrderViewById,AddDelivery} from '@/api/ordermanager/orderlist';
    export default {
      name: 'OrderEdit',
      props: {
        // 弹窗是否打开
        visible: Boolean,
        // 修改回显的数据
        data: Object,
        
      },
      data() {
        return {
          // 表单数据
          form: {},
          // 表单验证规则
          rules: {
            deliveryPlatform: [{ required: true, message: '请输入配送平台',trigger: 'blur'}],
            deliveryNo: [{required: true,message: '请输入配送单号',trigger: 'blur'}],
            deliveryUser: [{ required: true, message: '请输入配送人',trigger: 'blur'}],
            deliveryPhone: [{ required: true, message: '请输入配送电话',trigger: 'blur'}],
          },
          showData:{},
          // 提交状态
          loading: false,
          // 是否是修改
          isUpdate: false
        };
      },
      created(){
         this.queryDeliveryTypeEnums();
         this.queryDeliveryUser();
      },
      methods: {
        
        /* 保存编辑 */
        save() {
          //校验必填信息
          this.$refs['form'].validate((valid) => {
            if (!valid) {return false;}
            //日期时间
            this.loading = true;
            const saveOrUpdate = AddDelivery;
            console.log(this.form);
            saveOrUpdate(this.form)
              .then((msg) => {
                this.loading = false;
                this.$message.success(msg);
                this.updateVisible(false);
  
                //回调父组件方法
                this.$emit('done');
              })
              .catch((e) => {
                this.loading = false;
                this.$message.error(e.message);
              });
          });
        },
        setData(id){
          console.log("ss:"+id);
          QueryOrderViewById(id)
            .then((res) => {
              this.showData=res;
              //this.$util.assignObject(this.form, {...res});
               
           });
        },
        
        /* 更新visible */
        updateVisible(value) {
          //更新父组件中的visible的值
          this.$emit('update:visible', value);
          //更新文件列表对像
        },
      },  
      /* 监听visible属性变化 */
      watch: {
        visible(visible) {
          if (visible) {
            if (this.data && this.data.id) {
              //赋值this.form
              this.form={};
              this.setData(this.data.id);
              this.form.orderId=this.data.id;
              this.isUpdate = this.isUpdate = this.data.id !=null && this.data.id !=undefined;
            } else {
              this.form={}
              this.isUpdate = false;
            }
          } else {
            //移除校验结果
            this.$refs['form'].clearValidate();
            this.form = {};
          }
        }
      }
    };
  </script>
  